Repository navigation
Conversation
Before this change, `compiler_resources()` in `ignition/preparation/compile_pool.py` sampled `host_memory.available_bytes()` before calling `torch.cuda.empty_cache()`. On integrated/unified-memory GPUs (such as NVIDIA GB10), PyTorch's CUDA caching allocator pins physical host RAM, so flushing cached segments increases both `device_memory_info()` and `host_memory.available_bytes()`. Because `available` was never resampled after `torch.cuda.empty_cache()`, the subsequent `available = min(available, free)` discarded every byte reclaimed by the flush and kept the stale pre-flush host memory reading. In addition, the flush trigger only checked `free - headroom_bytes < device_bytes`, skipping `empty_cache()` both when unified-memory admission was bounded by the higher host compiler headroom/worker budget and when a discrete GPU's free memory fell below the admissible worker cap (`max_workers * device_bytes`). Finally, in `ForwardCache._prepare_ranks()`, `release_unused()` ran before the resource collection barrier without `torch.cuda.empty_cache()`, so peer ranks sharing a host could sample `available_bytes()` before other ranks returned cached CUDA segments. Flushing cached CUDA segments before sampling—and resampling both `free` and `available` after a flush on unified memory—solves the false `MemoryError` without relaxing memory budgets, headroom invariants, or worker sizing limits. In `ignition/preparation/compile_pool.py`, extracted `_DEFAULT_MAX_WORKERS = 8`, clamped `available = min(available, free)` once when `shared` is `True`, triggered `torch.cuda.empty_cache()` whenever `available - headroom < max_workers * worker_bytes` (on unified memory) or `free - headroom_bytes < max_workers * device_bytes` (on discrete GPUs), and resampled both `free` and `available` after flushing on unified memory (while leaving discrete GPUs to resample only `free`). In `ignition/preparation/aot.py`, added `torch.cuda.empty_cache()` immediately after `release_unused()` inside the existing `try/except` block preceding `dist.barrier(group=group)` in `ForwardCache._prepare_ranks()`. In `tests/preparation/test_compile_pool.py`, added CPU unit tests covering unified memory resampling across reclamation thresholds (POSIX and Windows), discrete GPU worker-capacity recovery (default and explicit `compile_workers > 8`), no-flush skips when memory already covers `max_workers`, and `_prepare_ranks()` flush-before-barrier ordering on both success and failure. Unified-memory and multi-rank preparations now account for freed PyTorch CUDA cache segments when budgeting forward compiler workers, preventing spurious `MemoryError` failures under tight physical memory and unlocking multi-worker admission when cached segments would otherwise cap worker counts. Validated with CPU unit tests (`CUDA_VISIBLE_DEVICES="" pytest -q tests/preparation/test_compile_pool.py tests/preparation/test_capture_order.py tests/preparation/test_forward_artifact_sharing.py tests/preparation/test_transient_retention.py tests/preparation/test_host_memory.py`: 160 passed, 0 failed). Validated end-to-end on 3x NVIDIA GB10 (121.7 GiB unified memory) exporting `DeepSeek-V4.1-Flash-1017` at TP3 (`--prefill-chunk-size 6144 --row-shard-prefill --row-shard-attention --image-concurrency 4 --max-concurrency 16 --mtp-draft-tokens 5 --vocabulary-parallel-sampling`): before this change, `Compile model forwards` failed in 2.5s with `MemoryError (8435 MiB available host memory, 8192 MiB headroom)`; after this change, the identical export admitted 3 compiler workers (`[1, 1, 1]`), compiled 51/51 forwards (1204.2s, 11.0-11.3 GiB `MemAvailable` with active compiler workers), captured all 193/193 CUDA graphs (804 MiB free at final graph), and passed `flare run` qualification (24/24 determinism 0.0000 nats KL, 23/24 top-1 vs TP4 0.0424 nats KL, -1.4593 NLL, 3.965s cold 32K needle pass, 61/61 concurrency, 4/4 concurrent image probe pass). Limitation: Windows unified-memory behavior is verified via CPU unit tests mocking `host_memory.os.name == "nt"` and `torch.cuda.mem_get_info` rather than live Windows hardware. Design-Signed-Off-By: Antigravity (Gemini); design-review=2e5b Signed-off-by: Jonathan Gutierrez <phialpha0@gmail.com>
Collaborator
|
A case file has been opened for 641. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Collaborator
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Ready To MergePR #641 cleanly fixes a verified memory-accounting bug in
Walkthrough
Merge Risk: Low · up to
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this change is needed and why this approach
Before this change,
compiler_resources()inignition/preparation/compile_pool.pysampledhost_memory.available_bytes()before callingtorch.cuda.empty_cache(). On integrated/unified-memory GPUs (such as NVIDIA GB10), PyTorch's CUDA caching allocator holds physical host RAM, so flushing cached segments increases bothdevice_memory_info()andhost_memory.available_bytes(). Becauseavailablewas never resampled aftertorch.cuda.empty_cache(), the subsequentavailable = min(available, free)discarded every byte reclaimed by the flush and kept the stale pre-flush host memory reading.In addition, the flush trigger only checked
free - headroom_bytes < device_bytes, skippingtorch.cuda.empty_cache()both when unified-memory admission was bounded by the higher host compiler headroom/worker budget (max(_HEADROOM_BYTES, headroom_bytes)+worker_bytes) and when a discrete GPU's free memory fell below the admissible worker cap (max_workers * device_bytes). Finally, inForwardCache._prepare_ranks(),release_unused()ran beforedist.barrier(group=group)withouttorch.cuda.empty_cache(), so peer ranks sharing a host could sample host memory before other ranks returned cached CUDA segments.Flushing cached CUDA segments before sampling—and resampling both
freeandavailableafter a flush on unified memory—fixes the stale memory accounting without relaxing headroom invariants or worker memory budgets.What changed
ignition/preparation/compile_pool.py: extracted_DEFAULT_MAX_WORKERS = 8, clampedavailable = min(available, free)once whensharedisTrue, triggeredtorch.cuda.empty_cache()wheneveravailable - headroom < max_workers * worker_bytes(on unified memory) orfree - headroom_bytes < max_workers * device_bytes(on discrete GPUs), and resampled bothfreeandavailableafter flushing on unified memory (while leaving discrete GPUs to resample onlyfree).ignition/preparation/aot.py: addedtorch.cuda.empty_cache()immediately afterrelease_unused()inside the existingtry/exceptblock precedingdist.barrier(group=group)inForwardCache._prepare_ranks(), preserving barrier progress and collective error reporting on failure.tests/preparation/test_compile_pool.py: added CPU unit tests covering unified-memory resampling across reclamation thresholds (POSIX and Windows viahost_memory.os), discrete-GPU worker-capacity recovery (default and explicitcompile_workers > 8), no-flush skips when memory already coversmax_workers, and_prepare_ranks()flush-before-barrier ordering on both success and failure.Claimed benefit
Unified-memory and multi-rank preparations accurately account for freed PyTorch CUDA cache segments when budgeting forward compiler workers, preventing spurious
MemoryErrorfailures under tight physical memory and unlocking additional compiler workers when cached segments would otherwise cap admission.Supporting evidence and material limitations
CUDA_VISIBLE_DEVICES="" pytest -q tests/preparation/test_compile_pool.py tests/preparation/test_capture_order.py tests/preparation/test_forward_artifact_sharing.py tests/preparation/test_transient_retention.py tests/preparation/test_host_memory.pypassed (160 passed, 0 failed).DeepSeek-V4.1-Flash-1017at TP3 (--ranks 3 --gpus 0 --max-concurrency 16 --mtp-draft-tokens 5 --prefill-chunk-size 6144 --image-concurrency 4 --expert-scale-compression csf --draft-head-quantization nvfp4 --markov-head-quantization fp8 --vocabulary-parallel-sampling --row-shard-prefill --row-shard-attention, paired with Pass candidate GPUs into filter_world_sizes during planning #635 and Enable cross-host SM121 RoCE TP3 for DeepSeek V4.1 local-inference-lab/hyperflare-recipes#103):Compile model forwardsin2.5swithMemoryError: host ... has 51 missing forwards but no capacity for a forward compiler (8435 MiB available host memory, 8192 MiB headroom)while ~4.9 GiB of freed preparation tensors remained in PyTorch's caching allocator.3compiler workers ([1, 1, 1]), compiled51/51forwards cleanly (1204.2s,11.0–11.3 GiBMemAvailablewith active compiler workers), captured all193/193CUDA graphs (804 MiBfree at final graph,97.66 GiBfixed GPU/rank), and passedflare runqualification (24/24determinism0.0000nats KL,23/24top-1 vs TP40.0424nats KL,-1.4593NLL,3.965scold 32K needle pass,61/61concurrency,4/4concurrent image probe pass).host_memory.os.name == "nt"andtorch.cuda.mem_get_inforather than live Windows hardware.Discord: nero